Use case: HASH process using SHA1 algorithm in IT mode

Sequence diagram

HASH process

  @startuml
  participant "Application" as App
  participant "HASH" as HASH
  participant "NVIC" as nvic

  == HASH initialization and Configuration ==
  App -> HASH: HAL_HASH_Init()
  note right : Configure the data type
  App <-- HASH:\n\n
  ==  HASH process with SHA1 algorithm ==
  group process: oneshot computing with single buffer
  App -> HASH: HAL_HASH_SHA1_Start_IT()
  note right : Compute and read the digest \nfrom the output buffer \n provided via a pointer
  nvic-> HASH : HAL_HASH_IRQHandler()
  App <-- HASH : HAL_HASH_DgstCpltCallback()
  end
  group process: computing with several input buffers
  App -> HASH: HAL_HASH_SHA1_Accmlt_IT()
  note right : write the first input buffer
  nvic-> HASH : HAL_HASH_IRQHandler()
  App->HASH : HAL_HASH_InCpltCallback()
  App -> HASH: HAL_HASH_SHA1_Accmlt_End_IT()
  note right :- feed the last input data buffer \n \n -retrieve the computed digest \nreturned via a pointer
  nvic-> HASH : HAL_HASH_IRQHandler()
  App->HASH : HAL_HASH_InCpltCallback() \n HAL_HASH_DgstCpltCallback()

  end
  App <-- HASH:\n\n\n\n
  == HASH De-initialization  ==
  App -> HASH: HAL_HASH_DeInit()

  @enduml

HMAC process

  @startuml
  participant "Application" as App
  participant "HASH" as HASH
  participant "NVIC" as nvic

  == HASH initialization and Configuration ==
  App -> HASH: HAL_HASH_Init()
  note right : Configure the data type,\n key and key size
  App <-- HASH:\n
  ==  HASH process with SHA1 algorithm ==
  group process: oneshot computing with single buffer
  App -> HASH: HAL_HMAC_SHA1_Start_IT()
  note right : Compute and read the digest \n from the output buffer \n provided via a pointer
  nvic-> HASH : HAL_HASH_IRQHandler()
  App <-- HASH : HAL_HASH_DgstCpltCallback()
  end

  group process: computing with several input buffers


  note over App, nvic: HAL1 does not support computing \n multi-buffers with HMAC process in IT mode
  App <-- HASH:\n\n\n\n\n\n\n\n\n\n\n
  end
  App <-- HASH:\n\n\n\n\n\n\n\n
  == HASH De-initialization  ==
  App -> HASH: HAL_HASH_DeInit()

  @enduml

Code snippet

HAL1

HAL2

/* This example is used with HASH processing mode */

uint8_t Msg65_Input[65] __attribute__ ((aligned (128)))= {
0x52, 0x43, 0x31, 0x5f, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65,
0x61, 0x50, 0x72, 0x6f, 0x6a, 0x65,0x63, 0x74, 0x5f, 0x53,
0x46, 0x55, 0x61, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65,
0x73, 0x61,0x53, 0x54, 0x4d, 0x33, 0x32, 0x32, 0x78, 0x47,
0x2d, 0x45, 0x56, 0x41, 0x4c, 0x61, 0x45, 0x57, 0x41, 0x52,
0x4d, 0x61, 0x53, 0x54, 0x4d, 0x33, 0x32, 0x32, 0x78, 0x47,
0x5f, 0x45, 0x56, 0x41, 0x4c};
uint8_t Sha1output[20]={0};


/* HASH Initialization and configuration */
hhash.Init.DataType = HASH_DATATYPE_8B;
HAL_HASH_Init(&hhash);




/* Process with oneshot HASH computing SHA1 algorithm */
HAL_HASH_SHA1_Start_IT(&hhash, Msg65_Input, 65, Sha1output);


/* Process with multi-buffer updating to compute SHA1 algorithm */
HAL_HASH_SHA1_Accmlt_IT(&hhash, Msg65_Input, 60);
/* Wait for input completion callback */
while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_READY);
/* Feed the last input data buffer to the peripheral and retrieve the digest */
HAL_HASH_SHA1_Accmlt_End_IT(&hhash, Msg65_Input+60, 5, Sha1output);
/* Wait for digest computation completed callback */
while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_READY);




/* De-initialization */
HAL_HASH_DeInit(&hhash);
/* This example is used with HASH processing */

 uint8_t Msg65_Input[65] __attribute__ ((aligned (128)))= {
 0x52, 0x43, 0x31, 0x5f, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65,
 0x61, 0x50, 0x72, 0x6f, 0x6a, 0x65,0x63, 0x74, 0x5f, 0x53,
 0x46, 0x55, 0x61, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65,
 0x73, 0x61,0x53, 0x54, 0x4d, 0x33, 0x32, 0x32, 0x78, 0x47,
 0x2d, 0x45, 0x56, 0x41, 0x4c, 0x61, 0x45, 0x57, 0x41, 0x52,
 0x4d, 0x61, 0x53, 0x54, 0x4d, 0x33, 0x32, 0x32, 0x78, 0x47,
 0x5f, 0x45, 0x56, 0x41, 0x4c};
 uint8_t Sha1output[20]={0};
 uint32_t sha1output_size;

 /* HASH Initialization */
 HAL_HASH_Init(&hhash, HAL_HASH);
 /* Configure SHA1 algorithm */
 hash_cfg.data_swapping  = HAL_HASH_DATA_SWAP_BYTE;
 hash_cfg.algorithm = HAL_HASH_ALGO_SHA1;
 HAL_HASH_SetConfig(&hhash, &hash_cfg);

 /* Process with oneshot HASH computing SHA1 algorithm */
 HAL_HASH_Compute_IT(&hhash, Msg65_Input, 65, Sha1output,
                     20, &sha1output_size);

 /* Process with multi-buffer updating to compute SHA1 algorithm */
 HAL_HASH_Update_IT(&hhash, Msg65_Input, 60);
 /* Wait for input completion callback */
 while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_IDLE);
 /* Feed the last input data buffer to the peripheral */
 HAL_HASH_Update_IT(&hhash, Msg65_Input+60, 5);
 /* Wait for input completion callback */
 while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_IDLE);
 /* Retrieve the digest */
 HAL_HASH_Finish(&hhash, Sha1output, 20, &sha1output_size, 1000);
 /* Wait for digest computation completed callback */
 while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_IDLE);
 /* De-initialization */
 HAL_HASH_DeInit(&hhash);

Key changes

  1. HAL2 uses unified interrupt APIs (compute/update/finish) and uses configuration functions to select the algorithm.

  2. HAL2 uses different completion callbacks (input and digest completion) and supports multi-buffer HMAC in IT mode.